package org.common.strategy2;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * ClassName: Factory
 * Package: org.common.strategy
 * Description:
 *
 * @Author: @weixueshi
 * @Create: 2024/7/19 - 21:42
 * @Version: v1.0
 */

/**
 * 策略工厂类
 */
public class Factory2 {
    private static final Map<String, AbstractStrategyFactory> STRATEGY_MAP = new ConcurrentHashMap<>();

    /**
     * 根据支付类型获取对应的策略
     * @param payType 支付类型
     * @return 策略对象
     */
    public static AbstractStrategyFactory getInvokeStrategy(String payType){
        return STRATEGY_MAP.get(payType);
    }

    /**
     * 注册支付策略
     * @param payType 支付类型
     * @param strategy 策略对象
     */
    public static void register(String payType, AbstractStrategyFactory strategy){
        if(payType == null && strategy == null){
            return;
        }
        STRATEGY_MAP.put(payType,strategy);
    }
}
